home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: jlilley@ix.netcom.com (John Lilley)
- Newsgroups: comp.lang.c++
- Subject: Re: Template Class Static Members Initialization
- Date: 29 Mar 1996 16:10:52 GMT
- Organization: Netcom
- Message-ID: <4jh22c$scq@dfw-ixnews6.ix.netcom.com>
- References: <31596E00.41C67EA6@cenparmi.concordia.ca>
- NNTP-Posting-Host: den-co11-03.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-NETCOM-Date: Fri Mar 29 10:10:52 AM CST 1996
- X-Newsreader: WinVN 0.99.7
-
- In article <31596E00.41C67EA6@cenparmi.concordia.ca>, didier@cenparmi.concordia.ca says...
- >Having troubles with the initialization of static members of a template class.
- >(C++ Primer, S.B. Lippman, 2nd edition, reprint June 93, Section 7.5, pp.369-371)
- >Any idea if that's due to my compiler or ?! Would that compile on yours?
-
- BC++4.5 has no problem...
-
- >#include <iostream.h>
- >
- >template <class T>
- >class Test
- >{
- > private:
- > T n;
- > public:
- > Test( T i ) : n(i) { count++; }
- > static int count;
- >};
- >
- >template <class T>
- > int Test<T>::count = 0;
- >
- >int main(int argc, char **argv)
- >{
- > Test<int> t1(1);
- > Test<double> t2(2.0);
- >
- > cout << Test<int>::count << endl;
- >}
-
- Try explicit instantiation of the static member (in a cpp file, not the header).
-
- int Test<int>::count = 0;
- int Test<double>::count = 0;
- etc.
-
- john lilley
-
-